﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tool.Helper
{
    public static  class FileHelper
    {
       /// <summary>
       /// 确保文件存在，不存在则创建
       /// </summary>
       /// <param name="filePath"></param>
       /// <returns></returns>
        public static void EnsureFileExists(this string filePath)
        {
            if (File.Exists(filePath))
            {
                return ;
            }

            // 获取目录
            string directory = Path.GetDirectoryName(filePath);
            if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory); // 自动创建多级目录
            }
           File.Create(filePath).Close();
        }

       
    }
}
